<?php

namespace backend\models;

use common\models\Company;
use yii\base\Model;
use yii\data\ActiveDataProvider;
class CompanySearch extends Company{
    public function rules()
    {
        // only fields in rules() are searchable
        return [
            [['email', 'name','id_company'], 'safe'],
        ];
    }

    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    public function search($params)
    {
        $query = Company::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => array( 
                'pageSize' => 10 ,
            ),
        ]);

        // load the seach form data and validate
        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        // adjust the query by adding the filters
        $query->andFilterWhere(['like', 'email', $this->email])
              ->andFilterWhere(['id_company', $this->id_company])  
              ->andFilterWhere(['like', 'name', $this->name]);

        return $dataProvider;
    }
}